import axios from 'axios'

export function getAdminStatisicInfo () {
  return axios.get('statistics/bsa').then(result => {
    if (result.isSuccess) {
      let data = result.data
      result.data = {
        systemUserCount: data.sysUserCount,
        systemActiveCount: data.activeUserCount,
        projectTotalCount: data.projectCount,
        contractTotalCount: data.contractCount
      }
    }
    return result
  })
}

export function getManagerStatisicInfo () {
  return axios.get('statistics/manager').then(result => {
    if (result.isSuccess) {
      let data = result.data
      result.data = {
        teamProjectTotalCount: data.projectCount,
        teamContractTotalCount: data.contractCount,
        teamSaleManCount: data.salesManCount,
        teamProjectMoney: data.serviceFeeSum
      }
    }
    return result
  })
}
export function getSalemanStatisicInfo () {
  return axios.get('statistics/salesman').then(result => {
    if (result.isSuccess) {
      let data = result.data
      result.data = {
        selfCustomerCount: data.cusCount,
        selfProjectCount: data.projectCount,
        selfContractCount: data.contractCount,
        selfProjectMoney: data.serviceFeeSum,
        draftCount: data.draftCount,
        receiptNotRecycleCount: data.recyclingReceiptCount,
        invoiceNotRecycleCount: data.recyclingInvoiceCount
      }
    }
    return result
  })
}
export function getTreasurerStatisicInfo () {
  return axios.get('statistics/treasurer').then(result => {
    if (result.isSuccess) {
      let data = result.data
      result.data = {
        monthContractCount: data.contractCount,
        monthProjectMoney: data.serviceFeeSum,
        monthRefundCount: data.returnFeeSum,
        monthInvoiceCount: data.invoiceTotalAmount,
        receiptNotRecycleCount: data.recyclingReceiptCount,
        invoiceNotRecycleCount: data.recyclingInvoiceCount
      }
    }
    return result
  })
}

export function getSalemanHistory () {
  return axios.get('statistics/salesman/tendency').then(result => {
    let list = []
    if (result.isSuccess) {
      result.data.forEach(element => {
        list.push({
          日期: element.month,
          签约数量: element.contractCount,
          业务金额: element.totalAmount
        })
      })
      list = list.reverse()
    }
    result.data = list
    return result
  })
}

export function getManagerHistory () {
  return axios.get('statistics/manager/tendency').then(result => {
    let list = []
    if (result.isSuccess) {
      result.data.forEach(element => {
        list.push({
          日期: element.month,
          签约数量: element.contractCount,
          业务金额: element.totalAmount
        })
      })
      list = list.reverse()
    }
    result.data = list
    return result
  })
}
